#include <learnRole.h>
#include <QTextEdit>
#include <QLayout>
#include <QDebug>

learnRole::learnRole(QWidget *parent)
    : QMainWindow(parent)
{
    this->resize(200,300);

    this->setWindowTitle(tr("Learn Role"));
   
    // QTextEdit *edit = new QTextEdit(this);
    // edit->setGeometry(10,10,780,580);

    // edit->setText(tr("This is a learnRole"));
    checkboox = new QCheckBox(this);
    checkboox->setText(tr("萝卜"));
    QLayout *layout = new QVBoxLayout(this);
    layout->addWidget(checkboox);

    checkboox1 = new QCheckBox(this);
    checkboox1->setText(tr("青菜"));
    layout->addWidget(checkboox1);

    checkboox2 = new QCheckBox(this);
    checkboox2->setText(tr("海参"));
    layout->addWidget(checkboox2);

    checkboox3 = new QCheckBox(this);
    checkboox3->setText(tr("胡桃"));
    layout->addWidget(checkboox3);
    QWidget *container = new QWidget(this);

    slider1 = new QSlider(this);
    slider1->setOrientation(Qt::Horizontal);
    taoqiLabel1 = new QLabel(this);
    taoqiLabel1->setText(tr("英俊值：:0"));
    layout->addWidget(slider1);
    layout->addWidget(taoqiLabel1);

    slider = new QSlider(this);
    slider->setOrientation(Qt::Horizontal);
    taoqiLabel = new QLabel(this);
    taoqiLabel->setText(tr("淘气值: 0")); // 初始化文本
    layout->addWidget(slider);
    layout->addWidget(taoqiLabel);
   
    
    
    price = 0;
    label = new QLabel(this);
    QString priceText = tr("价格：") + QString::number(price);
    label->setText(priceText);
    layout->addWidget(label);
  
    lineEdit = new QLineEdit(this);
    lineEdit->setPlaceholderText(tr("请输入内容"));
    layout->addWidget(lineEdit);
    
    

    container->setLayout(layout);
    this->setCentralWidget(container);
    connect(slider1, &QSlider::valueChanged, this, &learnRole::updateLabel1);
    connect(checkboox, &QCheckBox::clicked, this, &learnRole::on_check_price);
    connect(checkboox1, &QCheckBox::clicked, this, &learnRole::on_check_price);
    connect(checkboox2, &QCheckBox::clicked, this, &learnRole::on_check_price);
    connect(checkboox3, &QCheckBox::clicked, this, &learnRole::on_check_price);
    connect(slider, &QSlider::valueChanged, this, &learnRole::updateLabel);
    connect(lineEdit, &QLineEdit::textChanged, this, &learnRole::on_check_price);

}

learnRole::~learnRole()
{
    
}
 void learnRole::updateLabel(int value) 
{     
   taoqiLabel->setText(tr("淘气值: %1").arg(value)); // 更新标签文本
   on_check_price();
 }
 void learnRole::updateLabel1(int value) 
{     
   taoqiLabel1->setText(tr("英俊值: %1").arg(value)); // 更新标签文本
   on_check_price();
 }

void learnRole::on_check_price()
{
    price = 0;
 if(checkboox->isChecked())
 {
   price += 10;
 }
 if(checkboox1->isChecked())
 {
   price += 10;
 }
 if(checkboox2->isChecked())
 {
   price += 20;
 }
 if(checkboox3->isChecked())
 {
   price += 50;
 }
 if(slider->value() > 0)
 {
   price += slider->value() * 10;
 }
 if(slider1->value() > 0)
 {
   price += slider1->value() * 10;
 }
 if(lineEdit->text().length() > 0)
 {
  price += lineEdit->text().length() * 10;
 }
 
 QString priceText = tr("价格：") + QString::number(price);
    label->setText(priceText);

}